Completed
Push — master ( 971150...516dcf )
by
unknown
02:45
created

process.js ➔ prepend   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
c 1
b 0
f 0
nc 1
dl 0
loc 5
rs 9.4285
nop 2
1
import process from 'child_process'
2
import fse from 'fs-extra'
3
import path from 'path'
4
import fs from 'fs'
5
6
import {
7
  config
8
  ,abeExtend
9
} from '../'
10
11
function prepend(value, array) {
12
  var newArray = array.slice(0)
13
  newArray.unshift(value)
14
  return newArray
15
}
16
17
var abeProcess = function(name, args = []) {
18
  args = prepend(`ABE_WEBSITE=${config.root}`, args)
19
  args = prepend(`ABEJS_PATH=${__dirname}/../../../dist`, args)
20
21
  if (!abeExtend.lock.create(name)) {
22
    return false
23
  }
24
25
  var proc
26
  var file = `${__dirname}/../../cli/process/${name}.js`
27
  try {
28
    var stats = fse.statSync(file)
29
    if (stats.isFile()) {
30
      proc = process.fork(file, args)
31
    }
32
  }catch(err) {
33
    try {
34
      file = abeExtend.plugins.instance.getProcess(name)
35
      stats = fse.statSync(file)
36
      if (stats.isFile()) {
37
        proc = process.fork(file, args)
38
      }
39
    }catch(err) {
40
      console.log('process fork failed')
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
41
    }
42
  }
43
44
  if(typeof proc !== 'undefined' && proc !== null) {
0 ignored issues
show
Bug introduced by
The variable proc seems to not be initialized for all possible execution paths.
Loading history...
45
    proc.on('message', function( msg ) {
0 ignored issues
show
Unused Code introduced by
The parameter msg is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
46
      abeExtend.lock.remove(name)
47
      proc.kill()
0 ignored issues
show
Bug introduced by
The variable proc seems to not be initialized for all possible execution paths.
Loading history...
48
    });
49
    return true
50
  }
51
52
  return false
53
}
54
55
export default abeProcess